﻿using SEGIService.SGModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SEGIService.Service.Basic.Work;
using Newtonsoft.Json;

namespace SEGIService.Service.Basic.House
{
    public class SEGIHouseService(SqlSugarClient db, SigeWorkService _SigeWorkService) : SEGIBaseService(db)
    {
        public void HouseCertification()
        {
            // 这里添加房屋认证的逻辑
            // 目前只是一个占位符方法
            throw new SEGIException("房屋认证功能尚未实现。请稍后再试。");
        }

        /// <summary>
        /// 拉取四格欠费信息
        /// </summary>
        /// <param name="bodydata"></param>
        /// <returns></returns>
        public async Task<List<sigeArrearshouse10sum2>> sigearrears(object bodydata)
        {
            List<sigeArrearshouse10sum2> r = new List<sigeArrearshouse10sum2>();
            string json = string.Empty;
            int retry = 0;
            while (retry < 3)
            {
                try
                {
                    json = await _SigeWorkService.SendSigeWorkOrderRequestAsync("/v2/owes/query", bodydata);
                    break;
                }
                catch (Exception ex)
                {
                    retry++;
                    if (retry >= 3) { Console.WriteLine("拉取四格欠费信息异常qq" + ex.Message); return r; }
                    await Task.Delay(6000);
                }
            }

            var result = JsonConvert.DeserializeObject<ArrearsResponseModel>(json);

            if (result.code != "0")
            {
                Console.WriteLine("拉取四格欠费信息异常"+result.message);
                return r;
            }

            if (result.data != null)
            {
                return result.data.houseBills;
            }
            return r;
        }

    }
}
